from io import BytesIO

from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import UserInformation


def check(request):
    nick = request.POST.get('user_nick')
    pk = request.POST.get('aliyun_pk')
    if nick and pk:
        nick = nick[0:3] + '***' + nick[-3:]
        user = UserInformation.objects.filter(user_nick=nick).first()
        if not user:
            return HttpResponse('<p class="text-danger">抱歉，没有找到该用户，可能是数据未同步，可以2分钟后再次查询</p>')

        if user.real_name_type == "certified":
            if user.user_type == "newUser":
                return HttpResponse('<p class="text-success">恭喜你，是新用户，请在{}前购买哦</p>'.format(user.gmt_end))
            return HttpResponse('<p class="text-danger">抱歉，你不是新用户，推荐购买99一年的那款哈。但是没有返现哦</p>')
        else:
            return HttpResponse('<p class="text-danger">你还没有进行实名认证哈，请求实名认证后再来检测</p>')
    return HttpResponse('<p class="text-danger">请输入正确用户名和账号id</p>')



# from .Task import scheduler
#
# scheduler.start()